#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import pandas as pd
import os
from sklearn.metrics import average_precision_score
from sklearn.linear_model import LogisticRegression
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import train_test_split

# read data
homePath = "data"
trainPath = os.path.join(homePath, "train.csv")
testPath = os.path.join(homePath, "test.csv")
submitPath = os.path.join(homePath, "sample_submit.csv")
trainData = pd.read_csv(trainPath)
testData = pd.read_csv(testPath)
submitData = pd.read_csv(submitPath)

# 去掉没有意义的一列
trainData.drop("CaseId", axis=1, inplace=True)
testData.drop("CaseId", axis=1, inplace=True)

# 从训练集中分离标签
y = trainData['Evaluation']
trainData.drop("Evaluation", axis=1, inplace=True)

scaler = StandardScaler()
trainData = scaler.fit_transform(trainData)
testData = scaler.fit_transform(testData)

X_train, X_test, y_train, y_test = train_test_split(trainData,y,test_size=0.3)

#logistic
clf = LogisticRegression(C=0.5)
clf.fit(X_train, y_train)
y_pred = clf.predict_proba(X_test)[:, 1]
score = average_precision_score(y_test,y_pred)
print("score = {}".format(score))


















